home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / winclas.exe / WINCLASS.HPP < prev    next >
Text File  |  1991-07-08  |  13KB  |  347 lines

  1. #ifndef __cplusplus
  2. #error WindowsClasses Require C++!!
  3. #endif
  4.  
  5. #ifndef __COMPACT__
  6. #ifndef __LARGE__
  7. #error WindowsClasses Require Compact or Large memory model compilation
  8. #endif
  9. #endif
  10.  
  11. #ifndef __WINDOWS_H
  12. #include <windows.h>
  13. #endif
  14.  
  15. #ifndef __STRING_H
  16. #include <string.h>
  17. #endif
  18.  
  19. #ifndef __WINCLASS_HPP
  20. #define __WINCLASS_HPP
  21. #define __WINCLASSVER "1.40"
  22.  
  23.  
  24. class Window {
  25.     /*
  26.             WINCLASS.HPP
  27.                 Code by Michael Pittelkow
  28.                 Copyright (c) 1991, All Rights Reserved
  29.                 Hereby released as MostlyFreeWare.
  30.                 [That means, if you like it, and use it a lot, please send
  31.                  a donation to my college fund.  If you use it in something
  32.          that earns income for you, you by default fall into this
  33.          category.  If you like it, and don't use it much, or, just
  34.          don't feel it's worth anything, then don't feel obligated
  35.          to send anything.  Either way, pass this on to whomever
  36.          you please!]
  37.  
  38.  
  39.  
  40.                 Michael Pittelkow
  41.                 [summer]        [aug-may]
  42.                 10619 Zinran Circle     Friley 3399 Knapp
  43.                 Bloomington, MN  55438  Iowa State University
  44.                             Ames, IA 50012
  45.  
  46.                           BITNET    TNA32@ISUVAX
  47.                                          TELNET  tna32@ccvax.iastate.edu
  48.  
  49.               Find a bug?  Got a suggestion?  Got a snazzy addition?
  50.          Drop a line to the appropriate address (please use ONLY
  51.          snail mail during the summer) above.
  52.  
  53.                 Feel free to distibute this class, but please don't modify
  54.                 it, it's hard enough to keep up with my own code without
  55.                 trying to debug someone elses.  If you wish to distribute
  56.                 this file with your own derived classes, that's fine, but
  57.                 please put YOUR CLASSES in a SEPERATE FILE.  This module is
  58.                 set up to provide information for anything that would want
  59.                 to use it, such as defining the __WINCLASS_HPP.
  60.  
  61.             This class (window) is almost everything to set up a
  62.                 window.
  63.  
  64.                 The window class is given a classname that is the address
  65.                 of the ClassName pointer itself, followed by a "mp" postfix.
  66.                 This results in a guaranteed different name for each new
  67.                 variable of the class type, because they will always be at
  68.                 different memory addresses. [1672D4A:1.2:mp]
  69.  
  70.  
  71.  
  72.  
  73.   public        Window(LPSTR TitleBar,HANDLE hInstance,(FAR PASCAL....) lpfnWndProc());
  74.   public        Window(LPSTR TitleBar,HANDLE hInstance,(FAR PASCAL *lpfnWndProc)(), int nCmdShow);
  75.   public    SetClassname(LPSTR cname); Sets classname (see getclassname for default);
  76.   public    SethbrBackground(HBRUSH color); set background brush,
  77.                           default = COLOR_APPWORKSPACE+1
  78.   public        SetCreateStyle(DWORD style); for window creation time, see
  79.                     documentation for CreateWindow()
  80.                                         default = NULL
  81.   public        SetStyle(WORD style);      for class creation time, see
  82.                             documentation for RegisterClass()
  83.                                         default = NULL
  84.   public        SetWndProc((FAR PASCAL *lpfnWndProc)()); default = DefWindowProc
  85.   public        SetIcon(HICON hIcon); default = IDI_APPLICATION
  86.   public        SetInitialCursor(HCURSOR hCursor); default = IDC_ARROW
  87.   public        SetInitialBackground(HBRUSH hbrBackground);  default = WHITE_BRUSH
  88.   public        SetInitialMenu(LPSTR MenuName); default = NULL
  89.   public        BOOL SetMenu(LPSTR MenuName);
  90.   public        SetParent(HWND hParent); default = NULL
  91.   public        SetInitialPosition(int x, int y); default = CW_DEFAULT
  92.   public        SetInitialSize(int width, int height); default = CW_DEFAULT
  93.   protected     RegisterAndOpen(int nCmdShow);
  94.   public        HWND GethWnd(void);  returns a handle to the window (for
  95.                       adding hooks into a new class).
  96.   public        LPSTR GetClassName(void); returns classname, a string that is
  97.                             made up of the address of a particular
  98.                                         class function, winclassed vers, and a postfix
  99.                     of mp, like "123412432A:1.2:mp", unless overridden
  100.                                         by a call to SetClassname
  101.   public        Close(void);  closes but does not deregister any information
  102.                         about the window, use Reopen() reopen.
  103.   public        Open(int nCmdShow); Registers and opens the window.
  104.   public        Reopen(int nCmdShow); Reopens a closed window.
  105.   private    MakeClassName(void); Makes the classname (see getclassname).
  106.  
  107.  
  108.  
  109.         */
  110.  
  111. protected:
  112.     WNDCLASS wc;
  113.         static defBackgroundBrush;
  114.         LPSTR lpszTitle;
  115.         DWORD      CreateStyle;
  116.         int       x;
  117.         int        y;
  118.         int       width;
  119.         int        height;
  120.         HWND         hParent;
  121.         HMENU        hMenu;
  122.         HWND        hWnd;
  123.         char         ClassName[30];
  124.         BOOL        WinClosed;
  125.  
  126.         void RegisterAndOpen(int nCmdShow)
  127.             {
  128.                  MakeClassName();
  129.                  RegisterClass(&wc);
  130.                  hWnd = CreateWindow(wc.lpszClassName,
  131.                          lpszTitle,
  132.                                 CreateStyle,
  133.                                 x,
  134.                                 y,
  135.                                 width,
  136.                                 height,
  137.                                 hParent,
  138.                                 hMenu,
  139.                                 wc.hInstance,
  140.                 NULL);
  141.                  ShowWindow(hWnd,nCmdShow);
  142.                  UpdateWindow(hWnd);
  143.                 }
  144.  
  145. private:
  146.     void MakeClassName(void)
  147.             {  LPSTR version = __WINCLASSVER;
  148.  
  149.                     wsprintf(ClassName,"%lX:%s:mp",ClassName,version);
  150.                 }
  151.  
  152.  
  153.  
  154. public:
  155.     void SetClassname(LPSTR clname)
  156.             {
  157.                  stpcpy(ClassName,clname);
  158.                 }
  159.         HWND GethWnd(void)
  160.             {
  161.                  return hWnd;
  162.                 }
  163.         LPSTR GetClassName(void)
  164.             {
  165.                  return ClassName;
  166.                 }
  167. void    SethbrBackground(HBRUSH color)
  168.         {
  169.                  wc.hbrBackground = color;
  170.                 }
  171.         Window(LPSTR TitleBar, HANDLE hInstance,long (FAR PASCAL *lpfnWndProc)(HANDLE hWnd,unsigned message, WORD wParam,LONG lParam))
  172.             {
  173.                  hWnd = NULL;
  174.                  WinClosed = TRUE;
  175.                  CreateStyle = NULL;
  176.                  lpszTitle = TitleBar;
  177.                  wc.hInstance = hInstance;
  178.                  wc.style = NULL;
  179.                  wc.lpfnWndProc = lpfnWndProc;
  180.                  wc.cbClsExtra = 0;
  181.                  wc.cbWndExtra = 0;
  182.                  wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  183.                  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  184.                  wc.hbrBackground = COLOR_APPWORKSPACE+1;
  185.                  wc.lpszClassName = ClassName;
  186.                  wc.lpszMenuName = NULL;
  187.                  x = CW_USEDEFAULT;
  188.                  y = CW_USEDEFAULT;
  189.                  height = CW_USEDEFAULT;
  190.                  width = CW_USEDEFAULT;
  191.                  hMenu = NULL;
  192.                  hParent = NULL;
  193.  
  194.                 }
  195.         void Reopen(int nCmdShow)
  196.             {
  197.                ShowWindow(hWnd,nCmdShow);
  198.                UpdateWindow(hWnd);
  199.               }
  200.         Window(LPSTR TitleBar ,HANDLE hInstance,long (FAR PASCAL *lpfnWndProc)(HANDLE hWnd,unsigned message, WORD wParam,LONG lParam), int nCmdShow)
  201.             {
  202.                  hWnd = NULL;
  203.                  WinClosed = TRUE;
  204.                  CreateStyle = NULL;
  205.                  lpszTitle = TitleBar;
  206.                  wc.hInstance = hInstance;
  207.                  wc.style = NULL;
  208.                  wc.lpfnWndProc = lpfnWndProc;
  209.                  wc.cbClsExtra = 0;
  210.                  wc.cbWndExtra = 0;
  211.                  wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  212.                  wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  213.                  wc.hbrBackground = COLOR_APPWORKSPACE+1;
  214.                  wc.lpszClassName = ClassName;
  215.